package com.twu.biblioteca;

public class Output {

    private String string;

    public Output(String string) {
        this.string = string;
    }

    public Output(User user) {
        this.string = "Name: " + user.name() + " -- Email: " + user.email() + " -- Phone: " + user.phoneNumber();
    }

    public Output(MenuList menuList) {
        convertMenuListToString(menuList);
    }

    public Output(BookList bookList) {
        convertBookListToString(bookList);
    }

    public Output(MovieList movieList) {
        convertMovieListToString(movieList);
    }

    public String string() {
        return string;
    }

    private void convertMenuListToString(MenuList menuList) {

        string = "";

        for (MenuItem item : menuList) {
            string += menuList.indexOf(item) + 1 + ". " + item.itemName();
            if (menuList.indexOf(item) < menuList.size()-1) string += "\n";
        }

    }

    private void convertBookListToString(BookList bookList) {

        string = "";

        for (Book book : bookList) {
            string += "Title: " + book.title() + " -- Author: " + book.author();
            if (bookList.indexOf(book) < bookList.size()-1) string += "\n";
        }

    }

    private void convertMovieListToString(MovieList movieList) {

        string = "";

        for (Movie movie : movieList) {
            string += "Title: " + movie.title() + " -- Year: " + movie.year() + " -- Director: " + movie.director() + " -- Rating: " + movie.rating();
            if (movieList.indexOf(movie) < movieList.size()-1) string += "\n";
        }

    }

}
